package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.CamboDetailBean;
import com.joplus.housekeeper.bean.CamboDialogBean;
import com.joplus.housekeeper.utils.StringUtils;

/**
 * Created by ccm on 2016/9/12 11:31
 */
public class CamboDialogAdapter extends BaseAdapter {

    private Context mContext;
    private CamboDialogBean bean2;
    private CamboDetailBean bean1;
    private int level;

    public CamboDialogAdapter(Context mContext, CamboDialogBean bean, int i) {
        this.mContext = mContext;
        bean2 = bean;
        level = i;
    }

    public CamboDialogAdapter(Context mContext, CamboDetailBean bean1) {
        this.mContext = mContext;
        this.bean1 = bean1;
    }

    @Override
    public int getCount() {

        if (bean2 != null) {

            return bean2.getMenuDTO().get(level).getMenuPriList().size();
        }
        if (!StringUtils.isEmpty(bean1.getStoredDTO().getPrivilegeList().get(0).getSerName())) {
            return bean1.getStoredDTO().getPrivilegeList().size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.item_combo_p, null);
        TextView tv = (TextView) convertView.findViewById(R.id.item_tv);
        if (bean2 != null) {
            if (bean2.getMenuDTO().get(level).getMenuPriList().get(position).getCount().equals("disCount")) {
                tv.setText(bean2.getMenuDTO().get(level).getMenuPriList().get(position).getPriName());
            } else {
                tv.setText(bean2.getMenuDTO().get(level).getMenuPriList().get(position).getPriName() + "(剩余:" + bean2.getMenuDTO().get(level).getMenuPriList().get(position).getCount() + ")次");
            }


        } else {
            if (bean1.getStoredDTO().getPrivilegeList().get(position).getFreeCount().equals("disCount")) {
                tv.setText(bean1.getStoredDTO().getPrivilegeList().get(position).getSerName());
            } else {
                tv.setText(bean1.getStoredDTO().getPrivilegeList().get(position).getSerName() + "(剩余:" + bean1.getStoredDTO().getPrivilegeList().get(position).getFreeCount() + ")次");
            }

        }


        return convertView;
    }
}


